package cn.lijiajia3515.cairo.auth.modules.account;

import cn.lijiajia3515.cairo.auth.modules.AuthRabbitConstants;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.Map;

import static org.springframework.amqp.rabbit.annotation.Exchange.FALSE;
import static org.springframework.amqp.rabbit.annotation.Exchange.TRUE;

public class AccountMessageHandler {

	@RabbitListener(
		bindings = {
			@QueueBinding(
				exchange = @Exchange(value = AuthRabbitConstants.Exchange.HFHK, type = ExchangeTypes.TOPIC, autoDelete = FALSE),
				value = @Queue(value = AuthRabbitConstants.Queue.ACCOUNT_SAVE_LOGS, durable = TRUE, autoDelete = FALSE),
				key = AuthRabbitConstants.Key.USER_SAVE),
		}
	)
	@Component
	public static class SaveUserHandler {
		@RabbitHandler
		public void handle(@Headers Map<String, Object> headers, @Payload String payload, Message message, Channel channel) {
			System.out.println("handleString payload = " + payload);
			System.out.println("handleString headers = " + headers);
			System.out.println("handleString message = " + message);
			System.out.println("handleString channel = " + channel);
		}

		@RabbitHandler
		public void handle(@Headers Map<String, Object> headers, @Payload SavedAccountMessage payload, Message message, Channel channel) {
			System.out.println("handleObject payload = " + payload);
			System.out.println("handleObject headers = " + headers);
			System.out.println("handleObject message = " + message);
			System.out.println("handleObject channel = " + channel);
		}
	}
}
